'use strict';
/**
 *
 * Created by deng on 16-3-25.
 */

angular.module('metalabOperationApp').controller('signInCtrl', ['$scope', 'Passport',
    function ($scope, Passport) {
        $scope.signIn = function () {
            //var emailParttern = /^.{1,}/;
            var emailParttern = /^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})?$/;
            //var mobileParttern = /^\d{11}/;
            //var mobileParttern = /^.{1,}/;
            var data = {
                password: $scope.passport.password,
                role: 'admin'
            };
            if (emailParttern.exec($scope.passport.username)) {
                data.email = $scope.passport.username;
            } else {
                data.mobile = $scope.passport.username;
            }
            //} else if (mobileParttern.exec($scope.passport.username)) {
            //    data.mobile = $scope.passport.username;
            //}
            Passport.signIn(data);
        };
    }
]);
